import { reactive, ref } from 'vue'
import { createStore } from 'vuex'
import { transTime } from '../config/transtime'
import { songurl, songdetail } from '../api/music_style';

export default createStore({
  state: {
    audio: ref('11111111'),
    nowplay: reactive({
      id: '',
      url: '',
      state: 'play',
      img: '',
      name: '',
      al: '',
      currentTime: "0:00",
      duration: 0,
      length: 0
    }),
    ifshowplaylist: false, //用于控制播放列表的显隐，
    playlist: [],
    cookie:localStorage.getItem('cookie')
  },
  mutations: {
    changesong: async (state) => {
      let data = await songurl(state.nowplay.id)
      state.nowplay.url = data.data[0].url
      let detaildata = await songdetail(state.nowplay.id)
      state.nowplay.name = detaildata.songs[0].name
      state.nowplay.al = detaildata.songs[0].al.name
      state.nowplay.duration = transTime(detaildata.songs[0].dt / 1000)
      state.nowplay.img = detaildata.songs[0].al.picUrl
    }
  },
  actions: {
  },
  modules: {
  }
})

